﻿cmake_minimum_required(VERSION 3.22)

PROJECT(usbtool)

option(ENABLE_UDS "Unix Domain Socket" OFF)
option(ENABLE_PYTHON "add python wrap" OFF)
option(ENABLE_JAVA "add java wrap" OFF)

option(USING_8030USB "deamon using usb dev" ON)
option(USING_8030SDIO "deamon using sdio dev" OFF)
option(USING_8030UART "deamon using uart dev" OFF)

option(DAEMON_STATIC_LIB "build daemon as a static lib" OFF)
option(APP_STATIC_LIB "build ar8030 as a static lib" OFF)

option(BUILD_TEST_APP "build test user application" ON)

option(BUILD_ARTOSYN_EXAMPLE "build example" OFF)

option(BUILD_RAM_INIT "build ram init sample" OFF)

option(BUILD_TUNTAP "build tuntap" ON)

option(BUILD_BW_UPDATE_DEMO "build bw update demo" ON)

option(BUILD_IMG_UPGRADE "build img upgrade demo" OFF)

option(BUILD_XDATA_TEST "build xdata test demo" OFF)

option(BUILD_WORK_MODE_CFG "build work mode cfg" OFF)

option(BUILD_BB_TEST "build bb test demo" ON)

option(USING_XDS_HDR "proccess pkt with xds hdr" ON)

if(USING_8030USB)
    add_definitions(-DDEV_8030_USB)
    message("daemon using 8030 usb")
endif()

if(USING_8030SDIO)
    add_definitions(-DDEV_8030_SDIO)
    message("daemon using 8030 sdio")
endif()

if(USING_8030UART)
    add_definitions(-DDEV_8030_UART)
    message("daemon using 8030 uart")
endif()

if(NOT USING_8030USB AND NOT USING_8030SDIO AND NOT USING_8030UART)
    message(FATAL_ERROR "must choose dev mode first!!")
endif()

if(USING_XDS_HDR)
    add_definitions(-DPKT_XDS_HDR)
    message("with xds hdr")
endif()

if(ANDROID)
    SET(ENABLE_JAVA ON CACHE BOOL "add java wrap" FORCE)
    SET(DAEMON_STATIC_LIB ON CACHE BOOL "build daemon as a static lib" FORCE)
    SET(APP_STATIC_LIB ON CACHE BOOL "build ar8030 as a static lib" FORCE)
    SET(BUILD_TEST_APP OFF CACHE BOOL "build test user application" FORCE)
    SET(BUILD_ARTOSYN_EXAMPLE OFF CACHE BOOL "build example" FORCE)
endif()

if(ENABLE_PYTHON OR ENABLE_JAVA)
    SET(ADD_WRAP ON CACHE BOOL "add wrap function" FORCE)
endif()

# msvc上添加utf-8支持
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")

# 显示编译过程
set(CMAKE_VERBOSE_MAKEFILE off)

if(ENABLE_UDS)
    add_definitions(-DENABLE_UDS)
endif()

if(WIN32)
    message(STATUS "using win32")

    if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
        link_directories(third_package/pthread/windows/win32)
        install(FILES third_package/pthread/windows/win32/pthread.dll DESTINATION bin)
        install(FILES third_package/pthread/windows/win32/pthread.dll DESTINATION dev_helper)
    else()
        link_directories(third_package/pthread/windows/x64)
        install(FILES third_package/pthread/windows/x64/pthread.dll DESTINATION bin)
        install(FILES third_package/pthread/windows/x64/pthread.dll DESTINATION dev_helper)
    endif()

    include_directories("third_package/pthread/windows")
    add_definitions("-DHAVE_STRUCT_TIMESPEC")
    add_definitions("-D_WINSOCK_DEPRECATED_NO_WARNINGS")
else()
    message(STATUS "using linux")
endif()

add_subdirectory("com")
include_directories("com")
link_directories(com)

add_subdirectory(app)
add_subdirectory(daemon)
add_subdirectory(dev_helper)
